package scparser.factory.ShaderFactory;

import java.awt.Color;
import java.io.IOException;

import javax.vecmath.Point3d;

import model.Scene;
import model.Spec;
import scparser.ParserHelper;
import scparser.factory.primitiveFactory.FactoryException;

public abstract class ShaderFactory {
	protected Scene scene;
	protected String name;
	
	public Spec getSpec(String line) throws FactoryException, IOException {
		Color color;
		line = line.replaceAll("\\{", "");
		line = line.replaceAll("\\}", "");
		String[] values = line.split(" ");
		String type = values[0] + values[1];
		float r,g,b;

		if (type == null || type.equals("")) {
			throw new FactoryException("shader type option missing");
		}
		Point3d p;
		p = ParserHelper.takePoint(line, "\"sRGB nonlinear\"");

		r = (float) p.x;
		g = (float) p.y;
		b = (float) p.z;

		color = new Color(r,g,b);
		return new Spec(color, (float)Double.parseDouble(values[values.length-1]));		
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ShaderFactory other = (ShaderFactory) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

}
